package com.zs.framework.mail.utils;

import com.zs.framework.mail.exception.MailClientException;
import org.springframework.util.StringUtils;

import java.util.Properties;

/**
 * @author zhougf
 * @version 1.0
 * @date 2020/07/28
 */
public class MailHelper {

    public static SendEmailProducer getSendEmailProducer(String sendAddress, String receiveAddress, String userName, String userPassword, String host, Integer port, String protocol ) {
        SendEmailProducer instance = SendEmailProducer.getInstance();
        boolean flag = StringUtils.isEmpty(sendAddress);
        if(flag) {
            throw new MailClientException("Create a mail producer failure. sendAddress, Access Key, Secret Key and Address can not be blank.");
        }
        Properties properties = new Properties();
        properties.setProperty("sendAddress", sendAddress);
        properties.setProperty("receiveAddress", receiveAddress);
        properties.setProperty("userName", userName);
        properties.setProperty("userPassword", userPassword);
        properties.setProperty("host", host);
        properties.setProperty("port", String.valueOf(port));
        properties.setProperty("protocol", protocol);
        instance.setProperties(properties);
        return instance;
    }
}
